package com.significantfiles.properties.config.metadata;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import com.significantfiles.properties.util.config.PropertiesBasedObjectFactory;


public class ConstructorMetaData<T> {

	private final Constructor<T> constructor;

	private final ConstructorType type;

	public ConstructorMetaData(final Constructor<T> constructor,
			final ConstructorType type) {
		this.constructor = constructor;
		this.type = type;
	}

	public T createInstance(final PropertiesBasedObjectFactory<T> ownerFactory) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
		final boolean passFactory = ConstructorType.FACTORY_BASED.equals(type);

		if (passFactory)
			return this.constructor.newInstance(ownerFactory);

		return this.constructor.newInstance();
	}
}
